home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tpb4_src.zip / MSGMOVE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-13  |  25KB  |  615 lines

  1. { TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen
  2.   Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault  
  3.   
  4.   Last modified  ::  8-25-88 8:30 pm 
  5. }
  6.  
  7. {$R-}                             {Range checking off}
  8. {$B-}                             {Boolean complete evaluation off}
  9. {$S-}                             {Stack checking off}
  10. {$I+}                             {I/O checking on}
  11. {$N-}                             {No numeric coprocessor}
  12.  
  13. Unit MsgMove;
  14.  
  15. Interface
  16.  
  17. Uses
  18.   TPCrt, Dos, TPDOS, Globals, Core1, Core2,
  19.   TAccess, TPSTRING, NetMisc, Misc;
  20.   
  21.   
  22. procedure record_msg(fname : DosFileName);
  23.  
  24. procedure make_fido_message(area            : Str13;
  25.                             source          : DosFileName;
  26.                             from_loc,
  27.                             to_loc          : LongInt;
  28.                             old_subj        : Str72;
  29.                             LocalEnter      : Boolean;
  30.                             to_full_name    : Str36;
  31.                             net, node       : Integer;
  32.                             FileAttach      : Boolean);
  33.                             
  34.                             
  35.   {==========================================================================}
  36.   
  37.   
  38. Implementation
  39.  
  40.  
  41.   procedure record_msg(fname : DosFileName);
  42.   
  43.   var
  44.     Tfile           : Text;
  45.     i, first_line,
  46.     last_line       : Integer;
  47.     to_fn, Fr_fn    : FirstName;
  48.     to_ln, Fr_ln    : LastName;
  49.     Str             : StrStd;
  50.     Tname           : DosFileName;
  51.     temp_user_rec   : user_list;
  52.     This            : AreaPtr;
  53.     OK              : Boolean;
  54.     
  55.   begin
  56.     repeat
  57.       WriteLn(Com);
  58.       OK := False;
  59.       if fname = '' then
  60.         Tname := prompt('Filename to save msg to', 12, 'ES')
  61.       else
  62.         Tname := fname;
  63.       if Tname <> ' ' then
  64.         begin
  65.           Assign(Tfile, Tname);
  66.           {$I-}
  67.           Reset(Tfile); {$I+}
  68.           if IoResult <> 0 then
  69.             OK := True;
  70.           if OK then
  71.             begin
  72.               {$I-}
  73.               Rewrite(Tfile); {$I+}
  74.               OK := (IoResult = 0);
  75.             end
  76.           else
  77.             begin
  78.               WriteLn(Com);
  79.               if ask('File already exists...use anyway', 'Y') then
  80.                 begin
  81.                   {$I-}
  82.                   Rewrite(Tfile); {$I+}
  83.                   OK := (IoResult = 0);
  84.                 end;
  85.             end;
  86.         end;
  87.     until OK or (not Online) or (Tname = ' ');
  88.     if OK and Online then
  89.       begin
  90.         WriteLn(Com);
  91.         if fname = '' then
  92.           Write(Com, 'Writing file...');
  93.         with summ_rec do
  94.           begin
  95.             if fname = '' then
  96.               begin
  97.                 if user_to = 0 then
  98.                   begin
  99.                     to_fn := 'ALL';
  100.                     to_ln := '';
  101.                   end
  102.                 else if user_to = user_loc then
  103.                   begin
  104.                     to_fn := user_rec.fn;
  105.                     to_ln := user_rec.ln;
  106.                   end
  107.                 else
  108.                   begin
  109.                     GetRec(DatF, user_to, temp_user_rec);
  110.                     to_fn := temp_user_rec.fn;
  111.                     to_ln := temp_user_rec.ln;
  112.                   end;
  113.                 if user_from = user_loc then
  114.                   begin
  115.                     Fr_fn := user_rec.fn;
  116.                     Fr_ln := user_rec.ln;
  117.                   end
  118.                 else
  119.                   begin
  120.                     GetRec(DatF, user_from, temp_user_rec);
  121.                     Fr_fn := temp_user_rec.fn;
  122.                     Fr_ln := temp_user_rec.ln;
  123.                   end;
  124.                 Str := FormTAD(date);
  125.                 This := AreaBase;
  126.                 while (This <> nil) and (This^.Area <> Area) do
  127.                   This := This^.next;
  128.                 WriteLn(Tfile);
  129.                 if num_prev = 255 then
  130.                   Write(Tfile, '<P>');
  131.                 case status of
  132.                   deleted :
  133.                     Write(Tfile, 'Deleted');
  134.                   Seen :
  135.                     Write(Tfile, 'Read');
  136.                   private :
  137.                     Write(Tfile, 'Private');
  138.                   public :
  139.                     Write(Tfile, 'Public');
  140.                   restricted :
  141.                     Write(Tfile, 'Restricted');
  142.                 end;
  143.                 WriteLn(Tfile, ' Message # ', num, '  ', This^.AreaName, ' Area ', ' Entered ',
  144.                   Str);
  145.                 WriteLn(Tfile, 'From: ', Fr_fn, ' ', Fr_ln);
  146.                 WriteLn(Tfile, '  To: ', to_fn, ' ', to_ln);
  147.                 WriteLn(Tfile, '  Re: ', subject);
  148.               end;
  149.             first_line := st_rec;
  150.             last_line := size;
  151.           end;                    {with sum_rec}
  152.         i := 1;
  153.         Seek(mesg_file, first_line);
  154.         WriteLn(Tfile);
  155.         while (i <= last_line) and Online do
  156.           begin
  157.             Read(mesg_file, mesg_rec);
  158.             WriteLn(Tfile, mesg_rec);
  159.             Inc(i);
  160.           end;
  161.         Close(Tfile);
  162.         if fname = '' then
  163.           WriteLn(Com, 'Complete');
  164.       end;                        {ok and online}
  165.   end;                            {procedure}
  166.   
  167.   
  168.   
  169.   procedure make_fido_message(area            : Str13;
  170.                               source          : DosFileName;
  171.                               from_loc,
  172.                               to_loc          : LongInt;
  173.                               old_subj        : Str72;
  174.                               LocalEnter      : Boolean;
  175.                               to_full_name    : Str36;
  176.                               net, node       : Integer;
  177.                               FileAttach      : Boolean);
  178.                               
  179.   var
  180.     to_fn, Fr_fn    : FirstName;
  181.     to_ln, Fr_ln    : LastName;
  182.     temp_user_rec   : user_list;
  183.     buffer          : array[1..512] of Byte;
  184.     mname,
  185.     FidoArea        : StrPr;
  186.     OK, node_entrd,
  187.     abort, created,
  188.     file_not_saved  : Boolean;
  189.     mfile           : Text;
  190.     high_msg_num,
  191.     i, offset,
  192.     number,
  193.     remaining,
  194.     nodes,
  195.     position        : Integer;
  196.     msgnum, reply   : Str10;
  197.     subj            : Str72;
  198.     file_time       : tad_array;
  199.     to_name,
  200.     from_name       : Str36;
  201.     DateStr         : Str20;
  202.     low             : Byte;
  203.     msg_line,
  204.     prev_line       : string;
  205.     msg_file,
  206.     text_file       : untype_file;
  207.     temp_area       : DosFileName;
  208.     temp_str        : string[4];
  209.     msg_footer      : string;
  210.     
  211.   begin
  212.     OK := True;
  213.     low := 1;
  214.     created := False;
  215.     temp_area := AreaReq;
  216.     AreaReq := Area;
  217.     Fido_sort(high_msg_num, number, msg_numbers);
  218.     AreaReq := temp_area;
  219.     Inc(high_msg_num);
  220.     Str(high_msg_num, msgnum);
  221.     if ((source = '') and local_online) then
  222.       begin
  223.         if LocalEnter or ask('Use editor to create file', 'Y') then
  224.           begin
  225.             created := LocalEnter;
  226.             if LocalEnter then
  227.               begin
  228.                 DispName := Area;
  229.                 if Pos('-', DispName) = 1 then
  230.                   Delete(DispName, 1, 1);
  231.                 mname := Copy(DispName, 1, 8)+'.MSG'
  232.               end
  233.             else
  234.               begin
  235.                 mname := prompt('Name of file to create', 12, 'ES');
  236.                 DispName := mname;
  237.               end;
  238.             if LocalEnter then
  239.               begin
  240.                 DispName := to_full_name;
  241.                 {$V-}
  242.                 caps_to_mixed(DispName) {$V+} ;
  243.                 DispName := '   To: '+DispName;
  244.               end;
  245.             DispName := PadCh(DispName, ' ', 10);
  246.             full_screen_edit(mname, 'W', file_not_saved);
  247.             if file_not_saved then
  248.               begin
  249.                 Assign(mfile, mname);
  250.                 {$I-}
  251.                 Reset(mfile); {$I+}
  252.                 if IoResult = 0 then
  253.                   begin
  254.                     Close(mfile);
  255.                     Erase(mfile);
  256.                   end;
  257.               end;
  258.           end
  259.         else
  260.           mname := prompt('Name of file in SYSTEM area to put into message', 12, 'ES');
  261.       end
  262.     else if source = '' then
  263.       mname := prompt('Name of file in SYSTEM area to put into message', 12, 'ES')
  264.     else
  265.       mname := source;
  266.       
  267.     if mname <> ' ' then
  268.       begin
  269.         Assign(mfile, mname);
  270.         {$I-}
  271.         Reset(mfile); {$I+}
  272.         if IoResult <> 0 then
  273.           begin
  274.             WriteLn(Com);
  275.             WriteLn(Com, 'Message build aborted.');
  276.             WriteLn(Com);
  277.             OK := False;
  278.           end;
  279.         if OK then
  280.           begin
  281.             if source = '' then
  282.               begin
  283.                 if (not LocalEnter) then
  284.                   begin
  285.                     WriteLn(Com);
  286.                     Write(Com, '   From: > ', UserFullName);
  287.                   end;
  288.                 if (not LocalEnter) and (not ask('    OK', 'Y')) then
  289.                   begin
  290.                     from_name := prompt('   From: ', 35, 'EL');
  291.                     from_name := StUpcase(from_name);
  292.                     OK := ((from_name <> 'QUIT') and (from_name <> ''))
  293.                   end             {get new FROM name}
  294.                 else
  295.                   from_name := StUpcase(UserFullName);
  296.               end
  297.             else
  298.               begin
  299.                 if from_loc = user_loc then
  300.                   begin
  301.                     Fr_fn := user_rec.fn;
  302.                     Fr_ln := user_rec.ln;
  303.                   end
  304.                 else
  305.                   begin
  306.                     GetRec(DatF, from_loc, temp_user_rec);
  307.                     Fr_fn := temp_user_rec.fn;
  308.                     Fr_ln := temp_user_rec.ln;
  309.                   end;
  310.                 if Fr_fn = 'SYSOP' then
  311.                   from_name := fido_sysop
  312.                 else
  313.                   from_name := Fr_fn+' '+Fr_ln;
  314.               end;
  315.             if OK then
  316.               begin
  317.                 if source = '' then
  318.                   begin
  319.                     if (not LocalEnter) then
  320.                       begin
  321.                         to_name := prompt('     To: ', 35, 'EL');
  322.                         to_name := StUpcase(to_name);
  323.                         if to_name = '' then
  324.                           to_name := 'ALL';
  325.                         OK := ((to_name <> 'QUIT') and online);
  326.                         if OK then
  327.                           begin
  328.                             subj := prompt('Subject: ', 71, 'EL');
  329.                             WriteLn(Com);
  330.                             if subj = '' then
  331.                               subj := '....';
  332.                           end;
  333.                       end
  334.                     else
  335.                       begin
  336.                         if to_full_name = '' then
  337.                           to_name := 'All'
  338.                         else
  339.                           to_name := to_full_name;
  340.                         OK := True;
  341.                         subj := old_subj;
  342.                       end;
  343.                   end
  344.                 else
  345.                   begin
  346.                     if to_loc = 0 then
  347.                       begin
  348.                         to_fn := 'ALL';
  349.                         to_ln := '';
  350.                       end
  351.                     else if to_loc = user_loc then
  352.                       begin
  353.                         to_fn := user_rec.fn;
  354.                         to_ln := user_rec.ln;
  355.                       end
  356.                     else
  357.                       begin
  358.                         GetRec(DatF, to_loc, temp_user_rec);
  359.                         to_fn := temp_user_rec.fn;
  360.                         to_ln := temp_user_rec.ln;
  361.                       end;
  362.                     if to_fn = 'SYSOP' then
  363.                       to_name := fido_sysop
  364.                     else
  365.                       to_name := to_fn+' '+to_ln;
  366.                     subj := old_subj
  367.                   end;
  368.                 if OK then
  369.                   begin
  370.                     if Area[1] <> '-' then
  371.                       begin
  372.                         if (not LocalEnter) then
  373.                           repeat
  374.                             node_entrd := False;
  375.                             repeat
  376.                               reply := prompt('Net  (or CR for List) ', 9, 'ES');
  377.                               if reply = '?' then
  378.                                 reply := ' ';
  379.                               if reply = ' ' then
  380.                                 begin
  381.                                   show_nets;
  382.                                   WriteLn(Com);
  383.                                   WriteLn(Com)
  384.                                 end;
  385.                             until (reply <> ' ') or (not Online);
  386.                             position := Pos('/', reply);
  387.                             if position <> 0 then
  388.                               begin
  389.                                 temp_str := Copy(reply, Succ(position), 4);
  390.                                 msg_hdr.dest_node := strint(temp_str);
  391.                                 Delete(reply, position, 5);
  392.                                 node_entrd := True
  393.                               end;
  394.                             msg_hdr.dest_net := strint(reply);
  395.                             check_net(msg_hdr.dest_net, offset, nodes, OK);
  396.                             if (not OK) and (msg_hdr.dest_net <> 0) then
  397.                               begin
  398.                                 WriteLn(Com, 'No such Net, try again.');
  399.                                 node_entrd := False
  400.                               end;
  401.                             abort := (msg_hdr.dest_net = 0);
  402.                           until OK or (not Online) or abort;
  403.                         if (not LocalEnter) then
  404.                           repeat
  405.                             if (not node_entrd) then
  406.                               begin
  407.                                 repeat
  408.                                   reply := prompt('Node (CR for List) ', 4, 'ES');
  409.                                   if reply = '?' then
  410.                                     reply := ' ';
  411.                                   if (reply = ' ') then
  412.                                     begin
  413.                                       show_nodes(offset, nodes);
  414.                                       WriteLn(Com);
  415.                                       WriteLn(Com)
  416.                                     end;
  417.                                 until ((reply <> ' ') and (reply[1] in ['0'..'9']))
  418.                                 or (not Online);
  419.                                 msg_hdr.dest_node := strint(reply);
  420.                               end;
  421.                             check_node(msg_hdr.dest_node, offset, nodes, OK);
  422.                             if (not OK) then
  423.                               begin
  424.                                 WriteLn(Com, 'No such Node, try again.');
  425.                                 node_entrd := False
  426.                               end;
  427.                           until OK or (not Online);
  428.                         WriteLn(Com);
  429.                         if LocalEnter then
  430.                           begin
  431.                             node_entrd := True;
  432.                             msg_hdr.dest_node := node;
  433.                             msg_hdr.dest_net := net;
  434.                           end;
  435.                         if ask('Make the message public', 'N') then
  436.                           clear_bit(low, 0);
  437.                         if ask('Send via Crash mail', 'Y') then
  438.                           set_bit(low, 1);
  439.                         if FileAttach then
  440.                           set_bit(low, 4)
  441.                       end
  442.                     else
  443.                       clear_bit(low, 0);
  444.                     GetTAD(file_time);
  445.                     DateStr := Fido_FormTAD(file_time);
  446.                     if from_name = 'SYSOP' then
  447.                       from_name := fido_sysop;
  448.                       
  449.                     with msg_hdr do
  450.                       begin
  451.                         FillChar(msg_from, 36, 0);
  452.                         FillChar(msg_to, 36, 0);
  453.                         FillChar(subject, 72, 0);
  454.                         FillChar(date, 20, 0);
  455.                         times := 0;
  456.                         orig_node := this_node;
  457.                         cost := 0;
  458.                         orig_net := this_net;
  459.                         prev_msg := $00;
  460.                         attr_low := low;
  461.                         attr_high := $01;
  462.                         next_msg := $00;
  463.                         {$V-}
  464.                         caps_to_mixed(from_name);
  465.                         Move(from_name[1], msg_from, Length(from_name));
  466.                         caps_to_mixed(to_name) {$V+} ;
  467.                         Move(to_name[1], msg_to, Length(to_name));
  468.                         Move(subj[1], subject, Length(subj));
  469.                         Move(DateStr[1], date, Length(DateStr));
  470.                       end;
  471.                       
  472.                     if Area = 'NETMAIL' then
  473.                       begin
  474.                         FidoArea := fidomail;
  475.                         msg_hdr.cost := node_hdr.node_cost;
  476.                       end
  477.                     else
  478.                       FidoArea := fidomail+'\'+Area;
  479.                     SetSect(FidoArea);
  480.                     Assign(fido_file, msgnum+'.MSG');
  481.                     {$I-}
  482.                     Rewrite(fido_file) {$I+} ;
  483.                     OK := (IoResult = 0);
  484.                     if OK then
  485.                       begin
  486.                         Write(fido_file, msg_hdr);
  487.                         Close(fido_file);
  488.                         Assign(fido_message, msgnum+'.TXT');
  489.                         {$I-}
  490.                         Rewrite(fido_message) {$I+} ;
  491.                         OK := (IoResult = 0);
  492.                         if OK then
  493.                           begin
  494.                             {$I-}
  495.                             ReadLn(mfile, prev_line) {$I+} ;
  496.                             prev_line := Detab(prev_line, 8);
  497.                             msg_line := prev_line;
  498.                             while (not EoF(mfile)) do
  499.                               begin
  500.                                 ReadLn(mfile, msg_line);
  501.                                 msg_line := Detab(msg_line, 8);
  502.                                 if (Pos(' ', msg_line) = 1) or (msg_line = '') then
  503.                                   prev_line := prev_line+CR+LF
  504.                                 else
  505.                                   prev_line := prev_line+' '+SoftCR;
  506.                                 if prev_line = ' '+SoftCR then
  507.                                   prev_line := CR+LF;
  508.                                 Write(fido_message, prev_line);
  509.                                 prev_line := msg_line;
  510.                               end;
  511.                             WriteLn(fido_message, msg_line);
  512.                             Close(mfile);
  513.                             if source <> '' then
  514.                               Erase(mfile);
  515.                             if created then
  516.                               begin
  517.                                 SetSect(HomName);
  518.                                 Erase(mfile);
  519.                                 if Pos('.', mname) <> 0 then
  520.                                   Delete(mname, Pos('.', mname), 4);
  521.                                 Assign(mfile, mname+'.BAK');
  522.                                 {$I-}
  523.                                 Reset(mfile); {$I+}
  524.                                 if IoResult = 0 then
  525.                                   begin
  526.                                     Close(mfile);
  527.                                     Erase(mfile);
  528.                                   end;
  529.                                 SetSect(FidoArea)
  530.                               end;
  531.                             Close(fido_message);
  532.                             Assign(msg_file, msgnum+'.MSG');
  533.                             {$I-}
  534.                             Reset(msg_file, 1) {$I+} ;
  535.                             OK := (IoResult = 0);
  536.                             if OK then
  537.                               begin
  538.                                 Seek(msg_file, FileSize(msg_file));
  539.                                 Assign(text_file, msgnum+'.TXT');
  540.                                 {$I-}
  541.                                 Reset(text_file, 1) {$I+} ;
  542.                                 OK := (IoResult = 0);
  543.                                 if OK then
  544.                                   begin
  545.                                     remaining := 512;
  546.                                     while remaining = 512 do
  547.                                       begin
  548.                                         BlockRead(text_file, buffer, 512, remaining);
  549.                                         BlockWrite(msg_file, buffer, remaining);
  550.                                       end;
  551.                                     if Area[1] = '-' then
  552.                                       begin
  553.                                         EchoMsgEntr := 2;
  554.                                         if ExistFile('ORIGIN') then
  555.                                           begin
  556.                                             Assign(orig_file, 'ORIGIN');
  557.                                             Reset(orig_file);
  558.                                             ReadLn(orig_file, sect_orig);
  559.                                             sect_orig := ' * Origin: '+sect_orig+
  560.                                             ' ('+my_zone+':'+my_net+'/'+my_node+')'
  561.                                             +CR+LF;
  562.                                             Close(orig_file);
  563.                                           end
  564.                                         else
  565.                                           sect_orig := orig_line;
  566.                                         msg_footer := tear_line+sect_orig+
  567.                                         seenby_line;
  568.                                         for i := 1 to Length(msg_footer) do
  569.                                           buffer[i] := Ord(msg_footer[i]);
  570.                                         BlockWrite(msg_file, buffer,
  571.                                           Length(msg_footer));
  572.                                       end
  573.                                     else
  574.                                       NetMsgEntr := 1;
  575.                                     for i := 1 to 5 do
  576.                                       buffer[i] := 0;
  577.                                     BlockWrite(msg_file, buffer, 5);
  578.                                     Close(msg_file);
  579.                                     Close(text_file);
  580.                                     Erase(text_file);
  581.                                     if (Area[1] <> '-') and (node_hdr.node_cost > 0) then
  582.                                       Write(Com, 'This message will cost ',
  583.                                         node_hdr.node_cost, ' cents. ');
  584.                                     if (area[1] <> '-') and (node_hdr.node_cost > 0) and
  585.                                     (not ask('Do you want to send it', 'Y')) then
  586.                                       begin
  587.                                         Erase(msg_file);
  588.                                         WriteLn(Com);
  589.                                         WriteLn(Com, 'Message not saved.');
  590.                                       end
  591.                                     else
  592.                                       begin
  593.                                         if area[1] <> '-' then
  594.                                           user_rec.acct_bal := user_rec.acct_bal-node_hdr.node_cost;
  595.                                         WriteLn(Com);
  596.                                         WriteLn(Com, 'Message built.');
  597.                                       end;
  598.                                   end
  599.                                 else
  600.                                   WriteLn(Com,
  601.                                     'Message not filed due to I/O problems.');
  602.                               end;
  603.                           end;
  604.                       end;
  605.                     SetSect(HomName);
  606.                   end;
  607.               end;             
  608.           end;            
  609.       end;                        {Name<>' '}
  610.   end;
  611.   
  612.   
  613. end.
  614. 
  615.